{layout name="layout/header" /}
<link href="root/css/plugins/footable/footable.core.css" rel="stylesheet">

<link href="root/css/plugins/switchery/switchery.css" rel="stylesheet">
<script src="root/js/plugins/switchery/switchery.js"></script>
<!--<link href="root/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">-->

<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>模板列表</h5>
                </div>
                <div class="ibox-content">
                    <p>
                        <!--<a href="{:url('add')}" class="btn btn-danger btn-outline refresh">新增</a>-->
                        <a href="#" class="btn btn-danger btn-outline" id="add">新增</a>
                        <button type="button" class="btn btn-primary btn-outline refresh">刷新</button>
                    </p>
                </div>
                <div class="ibox-content">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>名称</th>
                                <th>路径</th>
                                <th>备注</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                        {volist name="data.list" id="vo"}
                            <tr pid="{$vo.id}">
                                <td>{$vo.name}</td>
                                <td>{$vo.path}</td>
                                <td>{$vo.remark}</td>
                                <td>{$vo.addtime|date="Y-m-d H:i",###}</td>
                                <td>
                                    <a type="button" class="btn btn-primary btn-sm edit" href="#">编辑</a>
                                </td>
                            </tr>
                        {/volist}
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="12">
                                {$data.page}
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>

</div>


<script>
    $(document).ready(function() {
        var elem = document.querySelectorAll('.js-switch');
        elem.forEach(function(i,index){
            var a= "a" +index;
            a = new Switchery(i, {
                hours: '#1AB394'
            });
        });
        //新添扩展字段
        $('#add').click(function () {
            var url = "{:url('add')}";
            edit(url);
        });

        $('.edit').click(function () {
            var id = $(this).parent().parent().attr('pid');
            var url = "{:url('update')}"+"/id/"+id;
            edit(url);
        })
        function edit(url) {
            layer.open({
                type: 2,
                title: "模板编辑",
                // closeBtn: 0, //不显示关闭按钮
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                // shade: [0],
                area: ['1020px', '700px'],
                content: [url], //iframe的url，no代表不显示滚动条
            });
        }

        //产品删除
        $('.product_del').click(function(){
            var id = $(this).parent().parent().attr('pid');
            var $this = $(this);

            layer.confirm('确定删掉吗?', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url:"{:url('ajax_del')}",
                    type:'post',
                    data:{id:id},
                    dataType:'json',
                    success:function (data) {
                        if(data.code==1){
                            layer.msg(data.msg);
                            $this.parent().parent().remove();
                        }else {
                            layer.msg(data.msg);
                        }
                    }
                })
            }, function(){

            });

        });
    });

</script>
